<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Block_Post_List extends Core_Block {

	public function __construct() {
		App::objectSingleton('Core_Cookie')->init('frontend', 'post');
	}
	
	protected function _beforeRender() {
		$this->getChild('toolbar')->setCollection($this->getPostCollection());
	}
	
	public function getPostCollection() {
		return $this->getLayout()->getBlock('post_layer')->getCollection()->addVisibleFilter();
	}
	
	/**
	 * Modify the html string to enable image lazy load
	 *
	 * @param string $content html string
	 * @return string
	 */
	public function modifyContent($content) {
		$pattern = '/src="([^"]*)"/i';
		$replacement = 'src="http://s9.postimg.org/i9dwitj7v/loading.gif" data-src="${1}"';
		return preg_replace($pattern, $replacement, $content);
	}
}